package com.ikas.ai.framework.core.listener;

import com.alibaba.fastjson.JSON;
import com.ikas.ai.framework.core.event.NodeEvent;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @Description: 算法节点日志记录
 * @Author: qi.yilai
 * @Date: 2022/8/11 11:39
 * @Version: 1.0.0
 **/
@Slf4j
public class NodeLogListener implements NodeListener {

    @Override
    public boolean fireEvent(NodeEvent event) {
        log.info("节点信息-nodeId: {}, nodeInstance:{}, nodeType:{}, nodeName:{}, status:{}, result:{}, event:{}",
                event.getOwner().nodeId(),
                event.getOwner().nodeInstanceId(),
                event.getOwner().type().getName(),
                event.getOwner().name(),
                event.getOwner().status().getCode(),
                Objects.nonNull(event.getOwner().result()) ? JSON.toJSONString(event.getOwner().result()) : "",
                Objects.isNull(event.getTarget()) ? "" : event.getTarget().toString());
        return true;
    }
}
